<!doctype html>
<html class="no-js" lang="">

<head>
  <meta charset="utf-8">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <title>注册</title>
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

  <link rel="manifest" href="../site.webmanifest">
  <link rel="apple-touch-icon" href="../icon.png">
  <!-- Place favicon.ico in the root directory -->

  <link rel="stylesheet" href="../static/css/normalize.css">
  <link rel="stylesheet" href="../static/css/main.css">
  <link rel="stylesheet" href="../static/assets/css/zeroModal.css">
  <link rel="stylesheet" href="../static/css/index.css">
</head>

<body>
  <!--[if lte IE 9]>
    <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="https://browsehappy.com/">upgrade your browser</a> to improve your experience and security.</p>
  <![endif]-->

  <!-- Add your site or application content here -->

  <!-- <div class="header">     <div class="header-container">         <div class="title" onclick="goUrl('/index.html')">             <img src="../static/img/jnsqywhglxmk.png" alt="" >             <img src="../static/img/glfupt.png" alt="">         </div>          <ul class="info">             <li id="header-username">                 <img src="../static/img/user.png" alt="">                 <a id="header-username" href="/login">登录</a>             </li>             <li>                 <img src="../static/img/config.png" alt="">                 <a>设置</a>             </li>             <li>                 <img src="../static/img/message.png" alt="">                 <a href="../static/message">站内信</a>             </li>             <li>                 <a class="exit" onclick="doLogout()">退出</a>             </li>         </ul>     </div> </div>
 -->
  <div class="main">
    <div class="container-box sign">
      <div class="container-box-title">
        <img src="../static/img/title2.png" alt="">
      </div>

      <ul class="form">
        <li>
          <input class="input" type="text" name="corporateName" style="width: 297px" placeholder="申报单位名称"><span class="form-must">*</span>
          <input class="input" type="text" name="account" style="width: 140px" placeholder="登录名"><span class="form-must">*</span>
        </li>
        <li>
          <select name="" id="corporateType" style="width: 230px">
            <option value="2">市直单位</option>
            <option value="1">区县单位</option>
          </select><span class="form-must">*</span>
          <select name="" id="belongReginCode" style="width: 220px">
            <option value="3701">济南市</option>
          </select><span class="form-must">*</span>
          <p id="must-area" class="form-must" style="text-align: right; padding-right: 80px; margin: 5px auto; display: none;">请选择单位注册地所在区县</p>
        </li>
        <!-- <li  id="abc_tip" style="margin: -13px auto 6px auto; display: none"></li> -->
        <li>
          <input type="password" name="password" style="width: 140px" placeholder="密码"><span class="form-must">*</span>
          <input type="password" name="repassword" style="width: 140px" placeholder="确认密码"><span class="form-must">*</span>
          <input type="text" name="email" style="width: 140px" placeholder="邮箱"><span class="form-must">*</span>
        </li>
        <li>
          <input type="text" name="businessCode" style="width: 297px" placeholder="工商登记或组织机构代码"><span class="form-must">*</span>
          <input type="text" name="phoneNum" style="width: 140px" placeholder="电话"><span class="form-must">*</span>
        </li>
        <li>
          <input type="text" name="address" style="width: 297px" placeholder="联系地址">&nbsp;&nbsp;
          <input type="text" name="telPhoneNum" style="width: 140px" placeholder="手机">
        </li>
      </ul>

      <div class="actions">
        <button class="primary-btn" id="submit">注册</button>
        <button class="primary-btn" onclick="goUrl('../login.html')">返回</button>
      </div>
    </div>

  </div>

   <div class="footer">
    <p>作者</p>
    <p>地址：</p>
    <p>邮政编码：250000 技术支持：</p>
  </div>

  <script src="../static/js/modernizr-3.6.0.min.js"></script>
  <script src="../static/js/jquery-1.12.min.js"></script>
  <script src="../static/js/plugins.js"></script>
  <script src="../static/assets/scripts/zeroModal.min.js"></script>
  <script src="../static/js/main.js"></script>
  
  <!-- Google Analytics: change UA-XXXXX-Y to be your site's ID. -->
  <script>
    window.ga = function () { ga.q.push(arguments) }; ga.q = []; ga.l = +new Date;
    ga('create', 'UA-XXXXX-Y', 'auto'); ga('send', 'pageview')
  </script>

  <script>
    // TODO : 切换单位类型 二级变换

    var areas =
      '            <option value="370102">历下区</option>\n' +
      '            <option value="370103">市中区</option>\n' +
      '            <option value="370104">槐荫区</option>\n' +
      '            <option value="370105">天桥区</option>\n' +
      '            <option value="370112">历城区</option>\n' +
      '            <option value="370113">长清区</option>\n' +
      '            <option value="370124">平阴县</option>\n' +
      '            <option value="370125">济阳县</option>\n' +
      '            <option value="370126">商河县</option>\n' +
      '            <option value="370181">章丘市</option>\n' +
      '            <option value="370182">高新区</option>' 
    document.getElementById('corporateType').addEventListener('change', function (ev) {
      if(ev.target.value == 1){
    	  $('#must-area').css({display: 'block'})
        document.getElementById('belongReginCode').innerHTML = areas
      } else {
    	  $('#must-area').css({display: 'none'})
        document.getElementById('belongReginCode').innerHTML = '<option value="3701">济南市</option>';
      }
    })
  </script>
  <script>
    /**
     * 注册
     */
    document.getElementById('submit').addEventListener('click', function (ev) {
      console.log('submit');
      var inputs = document.querySelectorAll('input');
      console.log(inputs);

      var data = {}; // ajax request data

      inputs.forEach(function (item) {
        data[item.name] = item.value;
      })

      data.corporateType = $('#corporateType').val();
      data.belongReginCode = $('#belongReginCode').val();
      data.belongReginName = $('#belongReginCode option:selected').text();

      if(data.password != data.repassword){
        zeroModal.error('密码不一致');
        return;
      }
      if(!data.corporateName){
    	  zeroModal.error('请输入单位名称');
          return;
      }
      if(data.corporateName.toString().length<3){
    	  zeroModal.error('单位名称格式不正确');
          return;
      }
      if(!data.account){
    	  zeroModal.error('请输入登录名');
          return;
      }
      if(data.account.length<3){
    	  zeroModal.error('登录账号要大于3位');
          return;
      }
      if(!data.password||data.password.toString().length<3){
    	  zeroModal.error('密码长度要大于3位');
          return;
      }
      if(!data.email){
    	  zeroModal.error('请输入邮箱');
          return;
      }
      var reg = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$");
      if(!reg.test(data.email)){
    	  zeroModal.error('邮箱格式不正确');
          return;
      }
      if(!data.businessCode){
    	  zeroModal.error('请输入工商登记或组织机构代码');
          return;
      }
      if(!data.phoneNum){
    	  zeroModal.error('请输入电话');
          return;
      }
      if(data.phoneNum.toString().length<6){
    	  zeroModal.error('电话格式不正确');
          return;
      }
    /*   var isPhone=new RegExp("/^((\+?86)|(\(\+86\)))?(13[012356789][0-9]{8}|15[012356789][0-9]{8}|18[02356789][0-9]{8}|147[0-9]{8}|1349[0-9]{7})$/"); //手机
      if(!isPhone.test(data.phoneNum)){
    	  zeroModal.error('邮箱格式不正确');
          return;
      } */
      $.ajax({
        url: API_DOMAIN + 'user/culture/cultureCorporateRegist/doCultureCorporateRegist',
        xhrFields: {
          withCredentials: true
        },
        crossDomain: true,
        headers: {
          'X-Requested-With': 'XMLHttpRequest',
          'content-type': 'application/x-www-form-urlencoded;charset=utf-8'
        },
        method: 'POST',
        data: data,
        success: function (result) {
          if (result.statusCode === 200) {
              zeroModal.success({
                content: '注册成功',
                ok: true,
                okTitle: '登录',
                okFn: function () {
                  window.location.href = '../login.html';
                }
              })
            } else {
              zeroModal.error(result.message);
            }
        },
        error: function (err) {
          zeroModal.error(err);
        }
      })
    })
  </script>
</body>

</html>
